package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.inter.OnRVItemClickListener;
import com.wangtao.firstapp.inter.OnRVItemLongClickListener;
import com.wangtao.firstapp.modles.CategoryPictures;

/*
 * 晒单界面下分类标签的自定义GridView的适配器
 * Created by lanouhn on 16/8/26.
 */
public class    MyClassAdapter extends BaseAdapter {
    private Context context;
    private CategoryPictures pictures;

    public MyClassAdapter(Context context, CategoryPictures pictures) {
        this.context = context;
        this.pictures = pictures;
    }

    @Override
    public int getCount() {
        return pictures.getData().getCategory_list().size();
    }

    @Override
    public Object getItem(int position) {
        return pictures.getData().getCategory_list().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_mygridview1, null);
            holder = new ViewHolder();
            holder.iv_item_gridview1 = (ImageView) convertView.findViewById(R.id.iv_item_gridview1);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(pictures.getData().getCategory_list().get(position).getPic()).config(Bitmap.Config.RGB_565).into(holder.iv_item_gridview1);
        return convertView;
    }

    public class ViewHolder {
        private ImageView iv_item_gridview1;
    }
}
